XdmModule.NativeModule<T> MethodXdmModule.NativeModule(Of T) MethodXdmModule::NativeModule<T> Method

Returns a module defined by a native .NET type.

Syntax

Public Shared Function NativeModule(Of T)() As XdmModule
public static XdmModule NativeModule<T>()
public:
generic <T>
static XdmModule^ NativeModule<T>()
 

Type Parameters

T

The type that contains methods to expose.

Return Value

Type: XmlPrime.XdmModuleXmlPrime.XdmModuleXmlPrime::XdmModule^

A new instance of XdmModuleXdmModuleXdmModule containing functions representing methods from T.

Exceptions

ExceptionCondition
InvalidOperationExceptionInvalidOperationExceptionInvalidOperationException An InvalidOperationExceptionInvalidOperationExceptionInvalidOperationException is raised in the following conditions:

Remarks

For an example of the use of this function, see Modules.

Libraries of functions can be made available to an XQuery program, XPath expression or XSL transformation by adding them to the LibrariesLibrariesLibraries collection.

If T is annotated with the XdmModuleAttributeXdmModuleAttributeXdmModuleAttribute then the target namespace can be specified by the attribute. If the attribute is not present, or the namespace is not declared, then the namespace of the function library is a uri with the scheme clitype. The path of the URI is the full CLI name of the type.

Here are some examples:
TypeURI
MathMathMathclitype:System.Math
decimalDecimaldecimalclitype:System.Decimal
SpecialFolderSpecialFolderSpecialFolder clitype:System.Environment+SpecialFolder (note that this is an enumeration, and as such has no static methods to import, but this still serves as an example of how to reference a nested type)

T must be a non-generic class, otherwise a NotSupportedExceptionNotSupportedExceptionNotSupportedException is thrown.

 
 
Warning
Note that in order to ensure well defined behaviour, all functions used from within the XQuery program, XPath expression or XSL transformation should be pure and deterministic (that is, they should have no side-effects and the value returned from the function must depend only on the values of its arguments). How many times each function is called, whether the function is called and the order in which functions are called is undefined and will change based on how the query is optimized.
 

If T is annotated with the XdmModuleAttributeXdmModuleAttributeXdmModuleAttribute attribute, then only those methods marked with XdmFunctionAttributeXdmFunctionAttributeXdmFunctionAttribute will be included. If any of these methods fail to satisfy the conditions below then an InvalidOperationExceptionInvalidOperationExceptionInvalidOperationException is thrown.

If T is not annotated with the XdmModuleAttributeXdmModuleAttributeXdmModuleAttribute attribute, then only those methods satisfying the conditions below will be exported.

  • The method is public.
  • The method is not a generic method.
  • The exported name of the method is a valid NCName value.
  • The name of all the parameters are valid NCName values.
  • The return type is supported.
  • All the parameter types are supported.
  • None of the parameters are ref or out parameters.
  • None of the parameters are variable length argument lists.
  • If the method is overloaded, then no overload has the same number of arguments.

If a method has the same exported name and number of arguments as a method in a base class that would be exported, then the base class methods with the same name and number of arguments are excluded.

Exported method can be marked with the XdmFunctionAttributeXdmFunctionAttributeXdmFunctionAttribute which allows the exported name of the method to be overridden. The parameters and return values of an exported method can be marked with the XdmTypeAttributeXdmTypeAttributeXdmTypeAttribute attribute which specifies the XDM type of the arguments and return types of the exported function.

More information about how native methods are bound to XQuery functions can be found on the Native modules page.